<?php

namespace app\home\controller;

use app\home\validate\GoodsValidate;
use think\Controller;
use think\Request;

class Goods extends Base
{


	public function getGoodsList(){
		$goodsModel = new \app\home\model\Goods();

		$list = $goodsModel->field('id,name,image,price,createtime')->order('createtime desc')->limit(2)->select();

		if(!empty($list)){
			return success($list);
		}
		return error('暂无数据');
	}


	public function getOneGoods(){


		$goodsValidate = new GoodsValidate();

		$validateRes = $goodsValidate->goSceneCheck('getOneGoods');

		if($validateRes){
			return error($validateRes);
		}

		$id = (int)$this->request->post('id');
		$goodsModel = new \app\home\model\Goods();

		$item = $goodsModel->where('id',$id)->find();

		if(!empty($item)){
			return success($item);
		}
		return error('暂无数据');

	}


}
